package com.stox.ui.javafx.navigator.widget;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import com.stox.ui.javafx.core.util.MessageSource;
import com.stox.ui.javafx.core.widget.StoxStage;
import com.stox.ui.javafx.core.widget.ViewMenu;
import com.stox.ui.javafx.core.widget.wrapper.MenuItem;
import com.stox.ui.javafx.navigator.view.NavigatorView;
import com.stox.util.ApplicationContextUtil;

@Component
public class ViewNavigatorMenuItem extends MenuItem implements InitializingBean {
	
	public ViewNavigatorMenuItem() {
		super(MessageSource.getMessage("Navigator"), "Ctrl+N", "navigator.png");
	}
	
	public int getOrder() {
		return 0;
	}
	
	public void afterPropertiesSet() throws Exception {
		setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent arg0) {
				NavigatorView navigatorView = ApplicationContextUtil.getApplicationContext().getBean(NavigatorView.class);
				if(!StoxStage.getRoot().getChildren().contains(navigatorView)) {
					StoxStage.getRoot().getChildren().add(navigatorView);
				}
				navigatorView.open();
			}
		});
	}

	@Override
	public Class<?> getParentClass() {
		return ViewMenu.class;
	}

}
